package com.woniuxy.controller;

import com.woniuxy.entity.ManagerUser;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
 * @BelongsProject: java-85-course-code
 * @BelongsPackage: com.woniuxy.controller
 * @Author: LiTongMiao
 * @Date: 2022/2/10 16:51
 * @Description: TODO
 */
@RequestMapping("/UserManager")
@RestController
public class ManagerController {
    @RequestMapping("/addUser")
    public ModelAndView addUser(@Valid @RequestBody ManagerUser manager, BindingResult result){
        ModelAndView mv = new ModelAndView();
        if (result.hasErrors()) {
            FieldError fieldError = result.getFieldError();
            mv.addObject("binding",fieldError.getField()+""+result.getFieldError().getDefaultMessage());
        }
        mv.setViewName("/WEB-INF/jsp/error.jsp");
        return mv;
    }
}
